<!-- 账号密码登录页 -->
<template>
	<view class="uni-content">
		<uni-forms>
			<uni-forms-item name="username">
				<uni-easyinput :focus="focusUsername" @blur="focusUsername = false" class="input-box"
					:inputBorder="false" v-model="username" placeholder="请输入手机号/用户名/邮箱" />
			</uni-forms-item>
			<uni-forms-item name="password">
				<uni-easyinput :focus="focusPassword" @blur="focusPassword = false" class="input-box" clearable
					type="password" :inputBorder="false" v-model="password" placeholder="请输入密码" />
			</uni-forms-item>
		</uni-forms>
		<button class="uni-btn" type="primary" @click="pwdLogin">登录</button>
		<!-- 忘记密码 -->
		<!-- <view class="link-box">
			<view>
				<text class="forget">忘记了？</text>
				<text class="link" @click="toRetrievePwd">找回密码</text>
			</view>
			<text class="link" @click="toRegister">注册账号</text>
		</view> -->
	</view>
</template>

<script>
	import {login} from '@/api/index.js'
	export default {
		data() {
			return {
				"password": "",
				"username": "",
				"focusUsername": false,
				"focusPassword": false,

			}
		},
		onShow() {},
		methods: {
			/**
			 * 密码登录
			 */
			pwdLogin() {
				if (!this.username.length) {
					this.focusUsername = true
					return uni.showToast({
						title: '请输入手机号/用户名/邮箱',
						icon: 'none',
						duration: 2000
					});
				}
				if (!this.password.length) {
					this.focusPassword = true
					return uni.showToast({
						title: '请输入密码',
						icon: 'none',
						duration: 2000
					});
				}	
				
				let data={
					Account:this.username,
					Password:this.password,
				}
				login(data).then(res=>{
					if(res.code==0){
						uni.setStorageSync('quyu',res.quyu)
						uni.setStorageSync('token',res.ticket)
						uni.redirectTo({
							url: '/pages/index/index'
						});
					}else{
						uni.showToast({
							icon: 'error',
							title: res.msg
						})
					}
				}).catch(e=>{
					uni.showToast({
						icon: 'error',
						title: e.msg
					})
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.forget {
		font-size: 12px;
		color: #8a8f8b;
	}

	.link-box {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}

	.link {
		margin-top: 20px;
		font-size: 12px;
	}

	.uni-content {
		padding: 60rpx 60rpx;
	}

	.login-logo {
		display: none;
	}

	/* #ifndef APP-NVUE */
	@media screen and (min-width: 690px) {
		.uni-content {
			/*#ifndef H5 */
			padding: 0;
			max-width: 300px;
			margin: 10rpx auto;
			/* #endif
	  }
	}
	
	.uni-content view {
	  box-sizing: border-box;
	}
	/* #endif */

			.input-box {
				height: 44px;
				background-color: #F8F8F8 !important;
				border-radius: 0;
				font-size: 14px;
				// #ifndef APP-NVUE */
				display: flex;
				// /* #endif
				flex: 1;
			}

			.link {
				color: #04498c;
				cursor: pointer;
			}

			.uni-content ::v-deep .uni-forms-item__inner {
				padding-bottom: 8px;
			}

			.uni-btn {
				text-align: center;
				height: 40px;
				line-height: 40px;
				margin: 15px 0 10px 0;
				color: #FFF !important;
				border-radius: 5px;
				font-size: 16px;
			}
</style>